from marshmallow import Schema, fields, validate

class DrugPropertiesSchema(Schema):
    """药品属性模式"""
    isPrescription = fields.Boolean(load_default=True)
    isControlled = fields.Boolean(load_default=False)
    storageCondition = fields.Str()

class DrugUsageSchema(Schema):
    """药品用法用量模式"""
    dosage = fields.Str()
    frequency = fields.Str()
    route = fields.Str()

class DrugSchema(Schema):
    """药品模式"""
    drugCode = fields.Str(required=True)
    name = fields.Str(required=True)
    genericName = fields.Str()
    category = fields.Str(required=True, validate=validate.OneOf(['西药', '中成药', '中药饮片', '生物制品']))
    specification = fields.Str(required=True)
    dosageForm = fields.Str(required=True)
    manufacturer = fields.Str(required=True)
    approvalNumber = fields.Str()
    price = fields.Float(required=True)
    properties = fields.Nested(DrugPropertiesSchema)
    usage = fields.Nested(DrugUsageSchema)
    indications = fields.List(fields.Str())
    contraindications = fields.List(fields.Str())
    sideEffects = fields.List(fields.Str())
    alertQuantity = fields.Integer(load_default=100)
    status = fields.Str(validate=validate.OneOf(['启用', '禁用']), load_default='启用')

class DrugUpdateSchema(Schema):
    """药品更新模式"""
    name = fields.Str()
    genericName = fields.Str()
    category = fields.Str(validate=validate.OneOf(['西药', '中成药', '中药饮片', '生物制品']))
    specification = fields.Str()
    dosageForm = fields.Str()
    manufacturer = fields.Str()
    approvalNumber = fields.Str()
    price = fields.Float()
    properties = fields.Nested(DrugPropertiesSchema)
    usage = fields.Nested(DrugUsageSchema)
    indications = fields.List(fields.Str())
    contraindications = fields.List(fields.Str())
    sideEffects = fields.List(fields.Str())
    alertQuantity = fields.Integer()
    status = fields.Str(validate=validate.OneOf(['启用', '禁用']))

class DrugInventorySchema(Schema):
    """药品库存模式"""
    drugId = fields.Str(required=True)
    batchNumber = fields.Str(required=True)
    quantity = fields.Integer(required=True)
    manufacturingDate = fields.DateTime()
    expirationDate = fields.DateTime(required=True)
    location = fields.Str()
    supplier = fields.Str()
    purchasePrice = fields.Float()
    receiveDate = fields.DateTime()
    receiveBy = fields.Str()
    status = fields.Str(validate=validate.OneOf(['正常', '过期', '即将过期', '缺货']), load_default='正常')

class DrugInventoryUpdateSchema(Schema):
    """药品库存更新模式"""
    quantity = fields.Integer()
    location = fields.Str()
    status = fields.Str(validate=validate.OneOf(['正常', '过期', '即将过期', '缺货'])) 